from openpyxl import Workbook
from openpyxl.styles import Font,Alignment,Border,Side,PatternFill



# 创建一个工作簿和工作表
wb = Workbook()
ws = wb.active

# 创建一个字体对象
font = Font(name='宋体', size=14, bold=True, italic=True, color='FF0000')
# 将字体应用到单元格
ws['A1'].font = font

# 设置对齐方式
alignment = Alignment(horizontal='center', vertical='center')

# 将对齐方式应用到单元格
ws['A1'].alignment = alignment

# 创建一个边框对象
border = Border(left=Side(border_style='thin', color='000000'),
                right=Side(border_style='thin', color='000000'),
                top=Side(border_style='thin', color='000000'),
                bottom=Side(border_style='thin', color='000000'))
# 将边框应用到单元格
ws['A1'].border = border

# 创建一个填充对象
fill = PatternFill(start_color='FFFF00', end_color='FFFF00', fill_type='solid')

# 将填充应用到单元格
ws['A1'].fill = fill

# 设置数字格式
# ws['A1'].number_format = '0.00%'  # 百分比格式
ws['A1'].number_format = '#,##0.00'  # 货币格式

# 合并单元格
ws.merge_cells('A1:B1')

ws['A1']='12345679.4564'

# 保存工作簿
wb.save('styled.xlsx')